# The Kband Mapping: see README.md.

def map_place(x, y, n) -> int:
    return x * n + y

allline = []

def insideBand(x, y, band, n) -> bool:
    if x < 0 or y < 0 or x >= n or y >= n: return False
    return abs(x - y) <= band

def Mapping(n, p, b) -> int:
    x = p // n
    y = p % n
    if x == 0: ans = (y - x)
    else: ans = allline_low[x - 1] + b + (y - x) - max(b - x, 0)
    return ans


if __name__ == '__main__':
    n = int(input())
    band = int(input())
    band = min(n, band)
    # The process of counting the number of elements in band is O(n)
    allline_low = [0 for i in range(n)]
    for i in range(n):
        allline_low[i] = 2 * band + 1 - max(band - i, 0) - max(band + i - n + 1, 0)
    #print(allline_low)
    # Calculating the pre-sum of it
    for i in range(1, n):
        allline_low[i] += allline_low[i - 1]
    #print(allline_low)
    # The process of counting the number of elements in band is O(n^2)
    '''
    allline = [0 for i in range(n)]
    for i in range(n):
        for j in range(n):
            allline[i] += insideBand(i, j, band)
    print(allline)
    for i in range(1, n):
        allline[i] += allline[i - 1]
    print(allline)
    '''
    cnt = 0
    for i in range(n):
        for j in range(-band, band + 1):
        #for j in range(n):
            if (insideBand(i, j + i, band, n) == False): continue
            print(i, j + i, end = ' ')
            print(Mapping(n, map_place(i, j + i, n), band))
            cnt += 1
    # n, data, band = map(int, input().split())
    print(cnt, cnt == allline_low[-1])
